export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    userInfo: localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : {},
    role: ''
  },
  mutations: {
    INIT_USER_INFO (state, { token, userInfo, role }) {
      state.token = token
      state.userInfo = userInfo
      state.role = role
    },
    // 退出登录，清除缓存
    CLECR_USER_INFO (state) {
      state.token = ''
      state.userInfo = {}
      state.role = ''
      localStorage.removeItem('token')
      localStorage.removeItem('userInfo')
      localStorage.removeItem('role')
    }
  }
}
